﻿@{
    ViewBag.Title = "RoleUsers";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    <link href="@Url.Content("~/Content/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.ztree.all-3.0.min.js")" type="text/javascript"></script>
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        var _rowId = "";
        var prepage = this;
        $(document).ready(function () {
            //更新皮肤
            funGridInit();
        });
//        function Save(t) {
//            // $.funSaveForm("/SystemManage/Role/SaveRole", "formDetail", function (d) {
//            // $("#Role_ID").val(d);
//            parent.asyncbox.tips('保存成功!', 'success');
////            MainFrame().$(MainFrame().gridId).trigger("reloadGrid");//此处不需要刷新父页面
//            parent.$.close(t.id);

//            //});
//        }
        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }
        function GetUsers() {
            //            //选择用户
            var id = '@ViewBag.RoleId';
            u = "/SystemManage/Role/RoleUserList?RoleId=" + id;
            if (id != null) {
                parent.asyncbox.open({
                    url: u,
                    data: '',
                    title: "选择用户",
                    width: 500,
                    height: 340,
                    scroll: 'no',
                    modal: true,
                    btnsbar: parent.$.btn.OKCANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                    callback: function (action, opener) {
                        var t = this;
                        if (action == 'ok') {
                            if (DialogFrame($(this).attr("id")).Save(t, prepage))
                            return false;
                        }
                        if (action == 'cancel') {

                        }
                    }
                });
            }
        }
        function RemoveUsers() {
            //移除用户
            var userid = $(gridId).getCell(_rowId, "User_ID");
            var roleid = $(gridId).getCell(_rowId, "Role_ID");

            $.post("/SystemManage/Role/RemoveRoleUser/", { roleId: roleid, userid: userid }, function (d) {
                if (d == "" || d == null) {
                    parent.asyncbox.tips('移除成功!', 'success', 1000);
                }
                else {
                    parent.asyncbox.tips('移除失败!', 'error', 1000);
                }
                //
                funSearch();
            });

        }
        function funSearch() {
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 51,
                width: $("#divGridContainer").width() - 2,
                url: '@Url.Content("~/SystemManage/Role/GetRoleUsers/")' + '@ViewBag.RoleId',
                autowidth: false,
                datatype: "json",
                sortname: 'Role_ID',
                multiselect: false,
                sortorder: 'desc',
                colModel: [
                { label: '用户编号', name: 'User_Code', width: 100 },
                { label: '用户名称', name: 'User_Name', width: 100 },
                { label: '角色名称', name: 'Role_Name', width: 120 },
                { label: '所在部门', name: 'Organization_Name', width: 200},
                { hidden: true, name: 'User_ID' },
                { hidden: true, name: 'Role_ID' },

   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    selectId = $(gridId).getCell(rowid, "Role_ID");
                    _rowId = rowid;
                },
                ondblClickRow: function (rowid) {
                    _rowId = rowid;
                },
                beforeRequest: function (d) {
                    // $(gridId).jqGrid('setGridParam', { postData: data });
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }
    </script>
    <div class="ui-layout-north">
        <div class="buttonlist" style="float: right; height: 34px; line-height: 36px; margin-right: 20px;">
            <a  onclick="funSearch()" class="button green"><span class="icon-botton" style="background: url('/Content/16/search.png') no-repeat scroll 0px 4px;"></span>刷新</a>
            <a  onclick="GetUsers()" class="button green"><span class="icon-botton" style="background: url('/Content/16/group.png') no-repeat scroll 0px 4px;"></span>选择用户</a>
            <a  onclick="RemoveUsers()" class="button green"><span class="icon-botton" style="background: url('/Content/16/delete.png') no-repeat scroll 0px 4px;"></span>移除用户</a>
           
        </div>
    </div>
    <!--主窗体，页面都需要的div-->
<div id="divGridContainer" class="ui-layout-center" style="overflow: auto;">
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
